/**
 * 
 */
package lifemain;

/**
 * @author kin
 */

public class matrix {
	int n;
	int m;
	boolean [][] matr;
	
	public matrix(int _n, int _m) 
	{
		n=_n;
		m =_m;
		matr = new boolean[n][m];
		
		for (int k=0; k<n; ++k)
		{
			for (int t=0; t<m; ++t)
			{
				matr[k][t]=false;				
			}
		}
	}
	
		
	public matrix()
	{
		n=1000;
		m=n;
		matr = new boolean[n][m];

		for (int k=0; k<n; ++k)
		{
			for (int t=0; t<n; ++t)
			{
				matr[k][t]=false;				
			}
		}
	}
	
	synchronized void setPole(int i, int j)
	{
		matr[i][j]=true;
	}
	
	synchronized void nosetPole(int i, int j)
	{
		matr[i][j]=false;
	}
	
	synchronized boolean getPole(int i, int j) 
	{
		return matr[i][j];
	}
	
	synchronized matrix getNPole(int i, int j) 
	{
		int _i=i-1;
		int _j=j-1;
		if (_j<=0)
		{
			_j=m+_j;
		}
		if (_i<=0)
		{
			_i=n+_i;
		}
		
		matrix m_t = new matrix(3,3);
		for (int k=0; k<3; ++k)
		{
			for (int t=0; t<3; ++t)
			{
				int i1,j1;
				if (_i+k>=n)
				{
					i1=_i+k-n;
				}
				else 
				{
					i1=_i+k;
				}
				if (_j+t>=m)
				{
					j1=_j+t-m;
				}
				else 
				{
					j1=_j+t;
				}
				
				if (matr[i1][j1])
				{
					m_t.setPole(k,t);
				}
			}
		}
		return m_t;
	}
	
	synchronized int getN()
	{
		return n;
	}
	
	synchronized int getM()
	{
		return m;
	}
	synchronized void Mprint()
	{
		for (int k=0; k<n; ++k)
        {
                for (int t=0; t<m; ++t)
                {
                        if (matr[k][t]) {System.out.print("* ");}
                        else {System.out.print("- ");}

                }
                System.out.println("");
        }
	
	}
	
	
	
	synchronized boolean clearM()
	{
		int s=0;
		for (int k=0; k<n; ++k)
		{
			for (int t=0; t<m; ++t)
			{
				if (matr[k][t]==true) s++;
			}
		}
		if (s==0) return false;
		else return true;
	}
}
